/*
 * AnimationPathMgr.h
 *
 *  Created on: Apr 21, 2013
 *      Author: pk
 */

#ifndef ANIMATIONPATH_H_
#define ANIMATIONPATH_H_

#include <QObject>
#include <QTimer>
#include <QMap>
#include <QList>
#include <QColor>
#include <QPair>
#include <QMutex>


struct Point2D
{
    Point2D(double x, double y) : X(x), Y(y)
    {

    }

    double X, Y;
};

struct ReplayData
{
   ReplayData(Source* src) : last_index(-1), go_reverse(false), source(src)
   {

   }
   int last_index; bool go_reverse;
   Source* source;
};

class Source;


class AnimationPathMgr: public QObject {

	Q_OBJECT

public:
    static AnimationPathMgr *getInstance();
    void deleteInstance();
    void drawPaths();
    bool hasCurrentSourceRecordedPath() const;
    bool handlePathClick() const;
    QMap< QTimer*, ReplayData > getReplayTimers() const
    {
       return replayTimers;
    }

    QList< Source* > getRecordedSources() const
    {
       return recordedPaths.keys();
    }

public Q_SLOTS:

    void setSelectedSource(Source *selectedSource);
    void startRecording();
    void startReplayPath();
    void stopReplayPath();
    void editRecordedPath();

private Q_SLOTS:
    void recordPoints();
    void replayPoints();

private:
    double calcDistance(Point2D prev, Point2D next) const;
    AnimationPathMgr();
    ~AnimationPathMgr();

    void stopRecording();

    static AnimationPathMgr *_instance;

    Source *_selectedSource;
    QTimer _recordPointTimer;
    QMap< Source*, QList<Point2D> > recordedPaths;
    QMap< Source*, QColor> sourcePathColor;
    bool is_recording;
    Point2D lastRecordedPoint;
    QMap< QTimer*, ReplayData > replayTimers;
    Source* sourceSelectedForEdit;
};

#endif /* ANIMATIONPATH_H_ */
